package com.zhengsr.corelib.utils;

import io.reactivex.Flowable;
import io.reactivex.processors.FlowableProcessor;
import io.reactivex.processors.PublishProcessor;

/**
 * Created by zhengshaorui
 * time: 2018/10/7
 */

public class RxBus {
    private final FlowableProcessor<Object> mRxbus;
    private static class Holder{
        static final RxBus SINGLE = new RxBus();
    }
    public static RxBus getInstance(){
        return Holder.SINGLE;

    }
    private RxBus(){
        mRxbus = PublishProcessor.create().toSerialized();
    }

    public void post(Object object){
        mRxbus.onNext(object);
    }



    public <T> Flowable<T> toFlowable(Class<T> eventType) {
        return mRxbus.ofType(eventType);
    }




}
